var port = (process.env.VMC_APP_PORT || 3000);
var host = (process.env.VCAP_APP_HOST || 'localhost');
var http=require("http");
var fs=require("fs");
var url=require('url');
var path=require('path');
var server = http.createServer(function(request, response) {

    var pathname = url.parse(request.url).pathname;
    var realPath
    if(pathname=='/'){
        realPath= "assets/dist/"+'index.html'
    }else{
        realPath = "assets/dist/" + pathname;
    }


    fs.exists(realPath, function (exists) {

        if (!exists) {

            response.writeHead(404, {'Content-Type': 'text/plain'});

            response.write("This request URL " + pathname + " was not found on this server.");

            response.end();

        } else {

            fs.readFile(realPath, "binary", function(err, file) {

                if (err) {

                    response.writeHead(500, {'Content-Type': 'text/plain'});

                    response.end(err);

                } else {

                    response.writeHead(200, {'Content-Type': 'text/html'});

                    response.write(file, "binary");

                    response.end();

                }

             });

          }

      });

}).listen(port, function(){
    console.log('server started');
});

